package com.ds.web.ctrl;

import com.ds.persist.FilingResultVO;
import com.ds.persist.OrderDeclaraResultVO;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangyou
 * @date 2018/12/2
 */
@RestController
public class IndexCtrl {


    @GetMapping(value = "/index")
    @ResponseBody
    public JSONObject index() {
        System.out.println("index");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("a","b");
        return jsonObject;
    }


    /**
     * 备案审核结果
     * @param EData
     */
    @PostMapping(value = "/filing/result")
    public JSONObject filingResult(@RequestParam String EData){
        try {
            EData = URLDecoder.decode(EData,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(EData);
        //文档中要求的响应
        JSONObject jsonObject = JSONObject.fromObject(EData);
        JSONObject json = new JSONObject();
        json.put("declaraType",jsonObject.get("apprType"));
        json.put("coCode",jsonObject.get("coCode"));
        json.put("tradeCode",jsonObject.get("tradeCode"));
        json.put("codeId",jsonObject.get("codeId"));
        json.put("cargoCrossId",jsonObject.get("cargoCrossId"));
        json.put("rtnCode",jsonObject.get("rtnCode"));
        json.put("recvTime",jsonObject.get("apprTime"));
        json.put("brandId",jsonObject.get("brandId"));
        json.put("brandCode",jsonObject.get("brandCode"));
        System.out.println("响应");
        System.out.println(json.toString());
        return json;
    }

    /**
     * 订单审核结果
     * @param EData
     */
    @PostMapping(value = "/order_declara/result")
    public String orderDeclaraResult(@RequestParam String EData){
        try {
            EData = URLDecoder.decode(EData,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(EData);
        return "SUCCESS";
    }






}
